Fix transform() corrupting TRUE/FALSE/NULL column defaults into strings#764
Open
gaoflow wants to merge 1 commit into
Open
Fix transform() corrupting TRUE/FALSE/NULL column defaults into strings#764gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
quote_default_value() passed keyword-literal defaults (TRUE, FALSE, NULL) through self.quote(), wrapping them in quotes. So transform() rebuilt a column declared "INTEGER DEFAULT TRUE" as "INTEGER DEFAULT 'TRUE'", and a later default insert stored the text 'TRUE' instead of the integer 1 (likewise 'FALSE' for 0 and 'NULL' for null) - silent value corruption. Return these keyword literals unquoted, as already done for the CURRENT_TIME/DATE/TIMESTAMP literals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
table.transform()corruptsTRUE/FALSE/NULLkeyword-literal column defaults into string literals, silently changing the value future rows receive.Before the transform a default insert stored the integer
1; afterwards it stores the text'TRUE'. Same forFALSE(→'FALSE'instead of0) andNULL(→'NULL'instead of null). On anINTEGERcolumn the quoted'TRUE'isn't numeric, so it's stored as TEXT — a genuine type and value change.Cause
transform()rebuilds the table by re-emitting each column'sPRAGMA table_infodefault throughquote_default_value(). That method returns the value verbatim when it is already quoted, is aCURRENT_TIME/DATE/TIMESTAMPliteral, or ends with); otherwise it callsself.quote(). The keyword literalsTRUE,FALSEandNULLmatch none of those guards, so they get string-quoted.The fix
Return
TRUE/FALSE/NULLunquoted, mirroring the existingCURRENT_*handling. A populated/numeric/expression default is unaffected.Tests
Added
TRUE/FALSE/true/NULLcases to thequote_default_valueEXAMPLEStable, and a functionaltest_transform_preserves_keyword_literal_defaultsthat createsDEFAULT TRUE/FALSE/NULL, rebuilds viatransform(), and asserts the schema stays unquoted and a fresh default insert still yields1 / 0 / NULL. All new cases fail onmainand pass with the fix; the fulltest_default_value.py+test_transform.pysuites stay green (78 passed);black,flake8andmypyclean.📚 Documentation preview 📚: https://sqlite-utils--764.org.readthedocs.build/en/764/